Skip to content

test: improve coverage for use command#10345

Merged
joehan merged 4 commits intonextfrom
test/use-command
Apr 24, 2026
Merged

test: improve coverage for use command#10345
joehan merged 4 commits intonextfrom
test/use-command

Conversation

@joehan
Copy link
Copy Markdown
Member

@joehan joehan commented Apr 15, 2026

Description

Add comprehensive unit tests for src/commands/use.ts including alias manipulation, output validation, and input parsing.

Scenarios Tested

  • Successful execution of --add and --clear
  • Verification of interactive mode fallbacks

Sample Commands

npm run mocha -- 'src/commands/use.spec.ts'

### Description
Add comprehensive unit tests for `src/commands/use.ts` including alias manipulation, output validation, and input parsing.

### Scenarios Tested
- Successful execution of `--add` and `--clear`
- Verification of interactive mode fallbacks

### Sample Commands
`npm run mocha -- 'src/commands/use.spec.ts'`
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@joehan joehan changed the base branch from main to next April 23, 2026 22:11
@joehan
Copy link
Copy Markdown
Member Author

joehan commented Apr 23, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new test suite for the use command and makes a minor adjustment to the command's authentication hook. The review feedback focuses on adhering to the repository's TypeScript style guide by removing unnecessary type assertions and 'unknown' escape hatches in favor of proper interface usage.

Comment thread src/commands/use.spec.ts Outdated
projectNumber: "123",
displayName: "My Project",
resources: {},
} as unknown as projects.ProjectInfo);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The object provided to resolves already satisfies the projects.ProjectInfo interface. You can remove the as unknown as escape hatch to adhere to the repository style guide (Line 38).

Suggested change
} as unknown as projects.ProjectInfo);
} as projects.ProjectInfo);
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

Comment thread src/commands/use.spec.ts Outdated
} as unknown as projects.ProjectInfo);
sinon
.stub(projects, "listFirebaseProjects")
.resolves([{ projectId: "my-project" }] as unknown as projects.ProjectInfo[]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using as unknown as is an escape hatch that violates the repository style guide (Line 38). It is better to provide a complete mock object that satisfies the projects.ProjectInfo interface, even if some fields contain dummy data.

Suggested change
.resolves([{ projectId: "my-project" }] as unknown as projects.ProjectInfo[]);
.resolves([{ projectId: "my-project", projectNumber: "123", displayName: "My Project", resources: {} }] as projects.ProjectInfo[]);
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

Comment thread src/commands/use.spec.ts Outdated
detectProjectRootStub = sinon.stub(detect, "detectProjectRoot").returns("/path/to/project");
sinon
.stub(rcModule, "loadRC")
.callsFake((options: unknown) => (options as Record<string, unknown>).rc || new RC());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of unknown and a type cast here is an escape hatch (Style Guide Line 38). You can use a more specific type for the stub's argument to avoid the cast.

Suggested change
.callsFake((options: unknown) => (options as Record<string, unknown>).rc || new RC());
.callsFake((options: { rc?: RC }) => options.rc || new RC());
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

@joehan joehan requested a review from aalej April 23, 2026 22:36
Comment thread src/commands/use.ts Outdated
.option("--unalias <name>", "remove an already created project alias")
.option("--clear", "clear the active project selection")
.before(requireAuth)
.before((options: Options) => requireAuth(options))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This is functionally(I think) the same as .before(requireAuth), and since we use .before(requireAuth) everywhere else, we might want to use .before(requireAuth) for consistency.

Copy link
Copy Markdown
Contributor

@aalej aalej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! minor nit on .before((options: Options) => requireAuth(options))

@joehan joehan merged commit 9ae31c3 into next Apr 24, 2026
13 of 16 checks passed
@joehan joehan deleted the test/use-command branch April 24, 2026 17:31
joehan added a commit that referenced this pull request Apr 24, 2026
wandamora pushed a commit that referenced this pull request Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants